package reflect;


import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Scanner;

public class ReflectDemo6 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个类名:");
        String className = sc.nextLine();
        System.out.println("请输入一个方法名:");
        String methodName = sc.nextLine();
        Method method = null;
        try {
            Class cls = Class.forName(className);
            method = cls.getMethod(methodName,String.class,int.class);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        String wayName = method.getName();
        System.out.println("方法名:"+wayName);
        int num = method.getParameterCount();
        System.out.println("参数个数:"+num);
        Class[] paramTypes =method.getParameterTypes();
        for(Class paramType:paramTypes){
            System.out.println("参数类型:"+paramType);
        }


        int mod = method.getModifiers();
        switch (mod){
            case Modifier.PUBLIC:
                System.out.println("public");
                break;
            case Modifier.PRIVATE:
                System.out.println("private");
                break;
            case Modifier.PROTECTED:
                System.out.println("protected");
                break;
            default:
                System.out.println("default");
        }
    }
}
